<template>
  <div class="app_main">
    <div class="search_box">
      <el-form ref="searchForm" :inline="true" :model="searchForm" size="mini">
        <search-form-box>
          <template slot="showSearch">
            <el-form-item label="甲方名称" prop="part_a">
              <el-input v-model="searchForm.part_a" placeholder="请输入甲方名称" clearable></el-input>
            </el-form-item>
            <el-form-item label="合同编号" prop="contract_num">
              <el-input v-model="searchForm.contract_num" placeholder="请输入合同编号" clearable></el-input>
            </el-form-item>
            <el-form-item label="项目名称" prop="customer_name">
              <el-input v-model="searchForm.customer_name" placeholder="请输入项目名称" clearable></el-input>
            </el-form-item>
            <el-form-item label="子公司" prop="dept_id">
              <el-select v-model="searchForm.dept_id" clearable style="width: 200px">
                <el-option v-for="item in companyArr" :value="item.id" :label="item.head" :key="item.id"></el-option>
              </el-select>
            </el-form-item>
          </template>
          <template slot="hideSearch">
            <el-form-item label="下单时间" prop="fill_date_begin">
              <el-date-picker
                v-model="searchForm.fill_date_begin"
                type="date"
                placeholder="开始时间"
                format="yyyy 年 MM 月 dd 日"
                value-format="yyyy-MM-dd"
                clearable
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="至" prop="fill_date_end">
              <el-date-picker
                v-model="searchForm.fill_date_end"
                type="date"
                placeholder="结束时间"
                format="yyyy 年 MM 月 dd 日"
                value-format="yyyy-MM-dd"
                clearable
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="投放时间" prop="contractBeginDate">
              <el-date-picker
                v-model="searchForm.contractBeginDate"
                type="date"
                placeholder="开始时间"
                format="yyyy 年 MM 月 dd 日"
                value-format="yyyy-MM-dd"
                clearable
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="至" prop="contractEndDate">
              <el-date-picker
                v-model="searchForm.contractEndDate"
                type="date"
                placeholder="结束时间"
                format="yyyy 年 MM 月 dd 日"
                value-format="yyyy-MM-dd"
                clearable
              >
              </el-date-picker>
            </el-form-item>
          </template>
          <template slot="searchBtn">
            <el-form-item>
              <el-button size="mini" type="primary" plain @click="search">查询</el-button>
              <el-button size="mini" type="info" plain @click="resetForm('searchForm')">重置</el-button>
            </el-form-item>
          </template>
        </search-form-box>
      </el-form>
    </div>
    <!--    <el-row style="margin-bottom: 10px">-->
    <!--      <el-button @click="createContract" v-permission="'create_contract'" size="mini" type="primary">新增合同-->
    <!--      </el-button>-->
    <!--    </el-row>-->
    <div class="data_box">
      <el-table :data="tableData" border style="width: 100%" v-loading="tableLoading" size="mini">
        <el-table-column fixed="left" width="50" label="序号" align="center">
          <template slot-scope="scope">
            <span>{{ (listParams.page - 1) * listParams.page_size + scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="下单时间" width="120" prop="fill_date" align="center"></el-table-column>
        <el-table-column label="换画类型" width="100" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.type === 1" type="primary" size="mini">否</el-tag>
            <el-tag v-else type="success" size="mini">是</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="媒体形式" width="300" show-overflow-tooltip align="center">
          <template slot-scope="scope">
            <div v-for="item in scope.row.media_form">
              {{ item }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="甲方" width="120" show-overflow-tooltip prop="contractName" align="center"
        ></el-table-column>
        <el-table-column label="合同编号" width="120" prop="contract_num" align="center"></el-table-column>
        <el-table-column label="项目名称" width="300" show-overflow-tooltip prop="customerName" align="center"
        ></el-table-column>
        <el-table-column label="幅数" width="80" prop="point_num" align="center"></el-table-column>
        <el-table-column label="投放时间" width="180" align="center">
          <template slot-scope="scope">
            <el-tag type="primary" size="mini">{{ scope.row.dateRangeBeginDate + '~' + scope.row.dateRangeEndDate }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="所属子公司" width="100" align="center" prop="deptName"></el-table-column>
        <el-table-column label="公司抬头" min-width="300" align="center" show-overflow-tooltip prop="dept_head"
        ></el-table-column>
        <el-table-column label="业务员" width="150" align="center" show-overflow-tooltip prop="apply_user_name"
        ></el-table-column>
        <el-table-column fixed="right" label="操作" width="100" align="center">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="look(scope.row.id)">查看点位
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="searchForm.page"
      :page-sizes="[10, 20, 50, 100, 200, 400]"
      :page-size.sync="searchForm.page_size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      style="margin-top: 10px"
    >
    </el-pagination>
    <el-dialog title="查看具体点位" :visible.sync="centerDialogVisible" width="80%" top="30px" center @close="tmpData=[]">
      <div style="max-height: 600px;overflow-y: auto" v-loading="loading">
        <point-config :read-only="true" :tip-show="false" :data="tmpData"></point-config>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="centerDialogVisible = false">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import SearchFormBox from '@/components/SearchFormBox'
import { detail, dispatch_list, list } from '@/api/saleOrder'
import { get_company } from '@/api/system/department'
import PointConfig from '@/components/PointPlanSetting/pointConfig'
import { formatData } from '@/views/business/contract/util'

export default {
  name: 'market_sale_order',
  components: { PointConfig, SearchFormBox },
  data() {
    return {
      tableData: [],
      tableLoading: false,
      searchForm: {
        page: 1,
        page_size: 10,
        // 客户名称
        part_a: null,
        // 填表日期开始
        fill_date_begin: null,
        // 填表日期结束
        fill_date_end: null,
        // 分公司id
        dept_id: null,
        // 投放开始时间
        contractBeginDate: null,
        // 投放结束时间
        contractEndDate: null,
        manager: true,
        customer_name: null,
        contract_num: null
      },
      listParams: {
        page: 1,
        page_size: 10,
        // 客户名称
        part_a: null,
        // 填表日期开始
        fill_date_begin: null,
        // 填表日期结束
        fill_date_end: null,
        // 分公司id
        dept_id: null,
        // 投放开始时间
        contractBeginDate: null,
        // 投放结束时间
        contractEndDate: null,
        manager: true,
        customer_name: null,
        contract_num: null
      },
      total: null,
      companyArr: [],
      centerDialogVisible: false,
      loading: false,
      tmpData: []
    }
  },
  created() {
    this.initCompanyArr()
    this.getList()
  },
  methods: {
    handleSizeChange(val) {
      this.listParams.page_size = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listParams.page = val
      this.getList()
    },
    getList() {
      this.tableLoading = true
      dispatch_list(this.listParams).then(res => {
        this.tableLoading = false
        this.total = res.data.total
        this.tableData = res.data.records
      }).catch(() => {
        this.tableLoading = false
      })
    },
    search() {
      this.searchForm.page = 1
      this.listParams = Object.assign({}, this.searchForm)
      this.getList()
    },
    resetForm() {
      this.$refs.searchForm.resetFields()
      this.listParams = Object.assign({}, this.searchForm)
      this.getList()
    },
    /**
     * 初始化子公司数组
     */
    initCompanyArr() {
      get_company().then(res => {
        this.companyArr = res.data
      })
    },
    look(id) {
      this.centerDialogVisible = true
      this.loading = true
      detail({ id: id }).then(res => {
        this.tmpData = formatData(res)
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    }
  }
}
</script>

<style scoped lang="scss">
.app_main {
  padding: 20px 20px 0 20px;
}
</style>
